package ltd.newbee.mall.service.impl;

import ltd.newbee.mall.common.ServiceResultEnum;
import ltd.newbee.mall.dao.VideoMapper;
import ltd.newbee.mall.entity.Carousel;
import ltd.newbee.mall.entity.Video;
import ltd.newbee.mall.service.VideoService;
import ltd.newbee.mall.util.PageQueryUtil;
import ltd.newbee.mall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Zcq
 * @create: 2022-09-14 08:47
 **/
@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    VideoMapper videoMapper;


    @Override
    public String addVideo(Video video) {
        if (videoMapper.addVideo(video) > 0) {
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }

    @Override
    public String upadateVideo(Video video) {
        if (videoMapper.updateVideo(video) > 0) {
            return ServiceResultEnum.SUCCESS.getResult();
        }
        return ServiceResultEnum.DB_ERROR.getResult();
    }

    @Override
    public Boolean deleteBatch(Long[] ids) {
        if (ids.length < 1) {
            return false;
        }
        //删除数据
        return videoMapper.deleteBatch(ids) > 0;
    }

    @Override
    public PageResult getVideoPage(PageQueryUtil pageUtil) {
        List<Video> videos = videoMapper.findVideoList(pageUtil);
        int total = videoMapper.getTotalVideos(pageUtil);
        PageResult pageResult = new PageResult(videos, total, pageUtil.getLimit(), pageUtil.getPage());
        return pageResult;
    }

}
